﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YXShop.TemplateAction
{
    public partial class LabelParse
    {
        //回复标签替换
        public string CommentReplyInfo()
        {
            string mystyle = this.Label_Inserted;
            string str_CompositorType = this.GetParamValue("YX:CompositorType");//排列顺序
            string str_CompositorField = this.GetParamValue("YX:CompositorField");//排列字段
            string str_ShowRows = this.GetParamValue("YX:ShowRows");//显示行数
            string str_ShowColumns = this.GetParamValue("YX:ShowColumns");//显示列数
            string str_WhetherPagination = this.GetParamValue("YX:WhetherPagination");//是否分页
            string str_TempletLayout = this.GetParamValue("YX:TempletLayout");//布局方式
            string str_ContentCharacter = this.GetParamValue("YX:ContentCharacter");//内容长度
            string str_WhetherOmit = this.GetParamValue("YX:WhetherOmit");//是否省略
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            StringBuilder showContent = new StringBuilder();
            int Rows = 1;
            if (!string.IsNullOrEmpty(str_ShowRows))
            {
                if (ChangeHope.Common.ValidateHelper.IsNumber(str_ShowRows))
                {
                    Rows = Convert.ToInt32(str_ShowRows);
                }
            }

            int Columns = 1;
            if (!string.IsNullOrEmpty(str_ShowColumns))
            {
                if (ChangeHope.Common.ValidateHelper.IsNumber(str_ShowColumns))
                {
                    Columns = Convert.ToInt32(str_ShowColumns);
                }
            }
            int PageSize = Rows * Columns;

            int ContentLength = 8;
            if (!string.IsNullOrEmpty(str_ContentCharacter))
            {
                if (ChangeHope.Common.ValidateHelper.IsNumber(str_ContentCharacter))
                {
                    ContentLength = Convert.ToInt32(str_ContentCharacter);
                }
            }

            //评论ID
            string commentid = ChangeHope.WebPage.PageRequest.GetQueryString("q_commentid");
            if (commentid == "")
            {
                return "暂无回复内容。";
            }
            string productid = ChangeHope.WebPage.PageRequest.GetQueryString("q_productid");
            YXShop.BLL.Accessories.CommentReply crbll = new YXShop.BLL.Accessories.CommentReply();
            YXShop.BLL.Member.MemberAccount mabll = new YXShop.BLL.Member.MemberAccount();
            YXShop.BLL.Member.MemberRank mrbll = new YXShop.BLL.Member.MemberRank();
            ChangeHope.DataBase.DataByPage dataPage = crbll.GetList(" [order by] replytime desc", PageSize, " and commentid=" + commentid + "");
            if (dataPage.DataReader != null)
            {
                int count = 0;
                while (dataPage.DataReader.Read())
                {
                    count++;
                    string memberName = string.Empty;
                    string memberLevelImages = string.Empty;
                    string memberLevel = string.Empty;
                    YXShop.Model.Member.MemberAccount mamodel = mabll.GetModel(int.Parse(dataPage.DataReader["uid"].ToString()));
                    if (mamodel != null)
                    {
                        memberName = mamodel.UserId;
                        YXShop.Model.Member.MemberRank mrmodel = mrbll.GetModel(int.Parse(mamodel.UserGroup.ToString()));
                        if (mrmodel != null)
                        {
                            memberLevelImages = mrmodel.LogoPic;
                            memberLevel = mrmodel.Name;
                        }
                    }
                    string strContent = mystyle.ToString();
                    //回复人
                    if (strContent.IndexOf("[#Reply_UserName]") > -1)
                    {
                        strContent = strContent.Replace("[#Reply_UserName]", memberName);
                    }
                    //等级图片
                    if (strContent.IndexOf("[#Reply_LevelImage]") > -1)
                    {
                        if (string.IsNullOrEmpty(memberLevelImages))
                        {
                            memberLevelImages = sp.DummyPaht + "images/none_50.gif";
                        }
                        strContent = strContent.Replace("[#Reply_LevelImage]", memberLevelImages);
                    }

                    //等级
                    if (strContent.IndexOf("[#Reply_Level]") > -1)
                    {
                        strContent = strContent.Replace("[#Reply_Level]", memberLevel);
                    }

                    //回复内容
                    if (strContent.IndexOf("[#Reply_Conent]") > -1)
                    {
                        strContent = strContent.Replace("[#Reply_Conent]", dataPage.DataReader["content"].ToString());
                    }
                    //回复时间
                    if (strContent.IndexOf("[#Reply_DateTime]") > -1)
                    {
                        strContent = strContent.Replace("[#Reply_DateTime]", dataPage.DataReader["replytime"].ToString());
                    }
                    //第几楼
                    if (strContent.IndexOf("[#Reply_Storey]") > -1)
                    {
                        strContent = strContent.Replace("[#Reply_Storey]", count + "楼");
                    }
                    showContent.Append(strContent);
                    if (str_TempletLayout == "1")
                    {
                        if (count % Convert.ToInt32(str_ShowColumns) == 0)
                        {
                            showContent.Append("</tr><tr>");
                        }
                    }

                }
                if (str_WhetherPagination == "0")
                {
                    showContent.Append(dataPage.ReceptionToolBar);
                }
            }
            else
            {
                return "暂无回复内容。";
            }



            return showContent.ToString();
        }

    }
}
